/**
 * getters
 */

import axiosInstance from "../utils/axiosInstance"
import {
  formatCityList
} from "../utils/dataFormat"

export default {
    //getters可要，要不要，它主要就是方便了我们去取值操作
    loadingText(state) {
        return state.showLoadingConfig.loadingText;
    },
    isShowLoading(state) {
        return state.showLoadingConfig.isShowLoading;
    },
    isShowPreviewImage(state) {
        return state.previewImageConfig.isShowPreviewImage;
    },
    previewImageUrls(state) {
        return state.previewImageConfig.urls;
    },
    previewImageIndex(state) {
        return state.previewImageConfig.current;
    },
    isShowActionSheet(state) {
        return state.actionSheetConfig.isShowActionSheet;
    },
    actionItemList(state) {
        return state.actionSheetConfig.itemList;
    },
    async cityList() {
        //正常情况下，get会从state里面拿值
        let str = localStorage.getItem("cityList");
        let cityList = null;
        if (str) {
            //缓存里面有值
            cityList = JSON.parse(str);
        } else {
            //没有的时候就应该请求

            let resp = await axiosInstance.get("/maoyanApi/dianying/cities.json")
            cityList = formatCityList(resp.data.cts);
            localStorage.setItem("cityList", JSON.stringify(cityList));
        }
        return cityList;
    }

}